package cn.tedu.toa.management.sys.mapper;

import cn.tedu.toa.management.sys.entity.SysRoles;
import cn.tedu.toa.management.sys.entity.SysUsers;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.shiro.authc.IncorrectCredentialsException;

import java.util.List;

/**
 * <p>
 * 系统用户 Mapper 接口
 * </p>
 *
 * @author huaqian
 * @since 2021-09-09
 */
public interface SysUsersMapper extends BaseMapper<SysUsers> {
    List<SysUsers> selectUserList(String username);

    SysUsers selectUserByName(String userName);

    int insert(SysUsers user);

    int insertUserRoles(@Param("userId") Integer userId, @Param("roleIds") Integer[] roleIds);

    //修改用户状态
    int modifyUserValidByUserId(int userId,int valid);

    //根据username查询 用户菜单表中的 记录
    @Select("select role_id from sys_user_roles where user_id=#{userId}")
    List<Integer> selectUserRoleByuserId(int userId);

    @Delete("delete from sys_user_roles where user_id=#{userId}")
    int delUserRoleByUserId(int userId);

    @Select("select count(*) from sys_users where username=#{username} and id!=#{userId}")
    int checkUserName(int userId,String username);

    List<Integer> selectRoleIdsByUserId(Integer userId);

    @Update("update sys_users set password=#{password},salt=#{salt} where id=#{userId}")
    //更新密码
    int updatePwdByUserId(String password,String salt,Integer userId);

}
